package com.lrkj.property.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.property.domain.Employee;
import com.lrkj.property.service.IEmployeeService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 员工关联表Controller
 *
 * @author yajun_ren
 * @date 2022-03-16
 */
@RestController
@RequestMapping("/property/employee")
@Api(tags = "员工关联表")
public class EmployeeController extends BaseController
{
    @Autowired
    private IEmployeeService employeeService;

    /**
     * 查询关联员工
     */
    @ApiOperation(value = "查询关联员工", notes = "查询关联员工")
    @PreAuthorize("@ss.hasPermi('property:employee:list')")
    @GetMapping("/list")
    public TableDataInfo list(Employee employee)
    {
        startPage();
        this.changeParameter(employee.getParams());
        List<Employee> list = employeeService.selectEmployeeList(employee);
        return getDataTable(list);
    }

    /**
     * 导出员工关联表列表
     */
	@ApiOperation(value = "导出员工关联表列表", notes = "导出员工关联表列表")
    @Log(title = "员工关联表", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('property:employee:export')")
    @GetMapping("/export")
    public AjaxResult export(Employee employee)
    {
        List<Employee> list = employeeService.selectEmployeeList(employee);
        ExcelUtil<Employee> util = new ExcelUtil<Employee>(Employee.class);
        return util.exportExcel(list, "员工关联表数据");
    }

    /**
     * 获取员工关联表详细信息
     */
	@ApiOperation(value = "获取员工关联表详细信息", notes = "获取员工关联表详细信息")
    @PreAuthorize("@ss.hasPermi('property:employee:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(employeeService.selectEmployeeById(userId));
    }

    /**
     * 新增员工关联表
     */
    @ApiOperation(value = "新增员工关联表", notes = "新增员工关联表")
    @Log(title = "员工关联表", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('property:employee:add')")
    @PostMapping
    public AjaxResult add(@RequestBody Employee employee)
    {
        return toAjax(employeeService.insertEmployee(employee));
    }

    /**
     * 修改员工关联表
     */
    @ApiOperation(value = "修改员工关联表", notes = "修改员工关联表")
    @Log(title = "员工关联表", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('property:employee:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody Employee employee)
    {
        return toAjax(employeeService.updateEmployee(employee));
    }

    /**
     * 删除员工关联表
     */
    @ApiOperation(value = "删除员工关联表", notes = "删除员工关联表")
    @Log(title = "员工关联表", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('property:employee:remove')")
	@DeleteMapping
    public AjaxResult remove(@RequestBody Employee employee)
    {
        return toAjax(employeeService.deleteEmployeeByIds(employee));
    }
}
